package com.lonely.goods.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lonely.common.utils.SecurityUtils;
import com.lonely.goods.domain.dto.goods.AddGoodsNotesDTO;
import com.lonely.goods.domain.entity.SysGoods;
import com.lonely.goods.domain.entity.SysGoodsNotes;
import com.lonely.goods.mapper.SysGoodsNotesMapper;
import com.lonely.goods.service.IGoodsNotesService;
import com.lonely.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 黄志标
 * @date: 2025/6/25 15:42
 * @description: 商品备注接口实现
 */
@Service
public class GoodsNotesServiceImpl extends ServiceImpl<SysGoodsNotesMapper, SysGoodsNotes> implements IGoodsNotesService {

    @Autowired
    private IGoodsService goodsService;

    /**
     * 添加商品备注
     *
     * @param addGoodsNotesDTO
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addNotes(AddGoodsNotesDTO addGoodsNotesDTO) {
        SysGoods sysGoods = this.goodsService.getById(addGoodsNotesDTO.getGoodsId());
        Assert.notNull(sysGoods, "商品不存在");

        SysGoodsNotes sysGoodsNotes = new SysGoodsNotes();
        sysGoodsNotes.setGoodsId(addGoodsNotesDTO.getGoodsId());
        sysGoodsNotes.setNotes(addGoodsNotesDTO.getNotes());
        sysGoodsNotes.setCreateBy(SecurityUtils.getUserId());
        sysGoodsNotes.setUpdateBy(SecurityUtils.getUserId());
        super.save(sysGoodsNotes);
    }
}
